﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;

namespace Gundam_2._0_Alpha.src
{
    public class DestroyableObject
    {
        public int health, maxHealth;
        protected Sprite objectSprite;
        protected Sprite explosion = Sprites.CreateSprite(Resources.LoadBitmap("explode.png"), 1, 11, 120, 120);
        protected bool playerDestroyable, invunerable = false;
        private string name;

        public bool Invunerable
        {
            get { return invunerable; }
            set { invunerable = value; }
        }

        public Sprite ObjectSprite
        {
            get { return objectSprite; }
            set { objectSprite = value; }
        }

        public int Health
        {
            get { return health; }
            set { health = value; }
        }

        public string Name
        {
            get { return name; }
        }

        public DestroyableObject(string name,int health, Sprite objectSprite)
        {
            this.name = name;
            this.objectSprite = objectSprite;
            this.health = health;
            this.maxHealth = health;
        }

        public virtual void Draw()
        { }

        public virtual void Update(GameController gc)
        { }

        public virtual void TakeDamage(int damage,GameController gc)
        {
            if (this is Character && Core.Rnd() > (this as Character).StatModifier.AvoidanceMultiplier) return;
            if (this is Character) damage = (int)((float)damage * (this as Character).StatModifier.DefenseMultiplier);

            if (!invunerable)
            {
                health -= damage;
                explosion.Draw((int)(objectSprite.X + objectSprite.Width / 2 - explosion.Width / 2),(int)(objectSprite.Y + objectSprite.Height / 2 - explosion.Height / 2));    
                explosion.UpdateAnimation();
            }

            

            if (health <= 0)
                gc.GameStages.Peek().ToDelete.Add(this);
        }
    }
}
